﻿using System;
using System.Xml.Serialization;
using System.Web.Script.Serialization;

using Fuse8.DomainFramework.Domain;
using Fuse8.DomainFramework.BusinessService;

namespace Fuse8.ContentManagementFramework.Domain
{
    [Serializable]
    public partial class CmsWorkflowHistory : Int32EntityObject, ITrackingEntityObject
    {
        #region Linked field

        private CmsWorkflow _workflow;

        #endregion

        #region Properties    
        
        public Guid WorkflowId { get; set; }

        public int? UserGroupId { get; set; }

        public int? UserId { get; set; }

        public int WorkflowState { get; set; }

        public string WorkflowData { get; set; }

        public string WorkflowDataType { get; set; }

        public bool IsLatestState { get; set; }

        public string Notes { get; set; }       

        public int CreatedBy { get; set; }

        public DateTime DateCreated { get; set; }

        public int? LastUpdatedBy { get; set; }

        public DateTime? DateLastUpdated { get; set; }

        #endregion

        #region Linked property

        [XmlIgnore]
        [ScriptIgnore]
        public CmsWorkflow Workflow
        {
            get
            {
                if (_workflow == null)
                {
                    var businessFacade = new BusinessServiceFacade<CmsWorkflow, Guid>();
                    if (businessFacade != null)
                    {
                        _workflow = businessFacade.FindOne(WorkflowId);
                    }
                }

                return _workflow;
            }
            set
            {
                WorkflowId = value != null ? value.Id : Guid.Empty;

                if (_workflow != null)
                {
                    _workflow = _workflow.Id == WorkflowId ? value : null;
                }
                else
                {
                    _workflow = value;
                }
            }
        }

        #endregion

        public CmsWorkflowHistory()
        { }

        public override string TypeParameter
        {
            get 
            {
                return "WorkflowHistory";
            }
        }        
    }
}
